package{
	
	import com.greensock.TweenLite;
	
	import component.Image;
	
	import flash.display.DisplayObject;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.setTimeout;
	
	import module.Ball;
	import module.LoginPanel;
	import module.LogoShell;
	import module.Map;
	
	import org.papervision3d.view.BasicView;
	
	public class LogoBall2 extends BasicView{
		
		private var turnSpeed:int = 1; //旋转速度
		
		public function LogoBall2(){
			addEventListener(Event.ADDED_TO_STAGE,init);
		}
		
		private function init(e:Event):void{
			removeEventListener(Event.ADDED_TO_STAGE,init);
//			stage.color = 0;
			stage.frameRate = 40;
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			this.viewport.addEventListener(MouseEvent.CLICK,onClick);
			stage.addEventListener(Event.RESIZE,onResize);
			Global.stage = stage;
			preLoad();
			addChild(LoginPanel.instance);
			addChild(LogoShell.instance);
		}
		
		/**
		 * 预加载图片
		 * */
		private function preLoad():void{
			var batchNames:Array = [];
			for(var i:int=1;i<13;i++)batchNames.push("pic"+i+".jpg");
			Image.batchLoad("resource",batchNames,function():void{
				initMain();
			});
		}
		
		private function initMain():void{
			var map:Map =addChild(Map.instance) as Map;
			map.onResize();
			this.scene.addChild(Ball.instance);
			this.viewport.x = -400;
			this.startRendering();
		}
		
		override protected function onRenderTick(e:Event=null):void{
			super.onRenderTick();
			Ball.instance.localRotationY -= this.turnSpeed;
		}
		
		private function onClick(e:MouseEvent):void{
			Map.instance.tweenOp();
		}
		
		private function onResize(e:Event):void{
			for(var i:int = 0;i<numChildren;i++){
				var child:DisplayObject = this.getChildAt(i);
				if(child.hasOwnProperty("onResize")){
					(child as Object).onResize();
				}
			}
		}
		
	}
}